home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-24 | 9.3 KB | 365 lines | [TEXT/CWIE] |
- // CLG_CharsGrid.cp
- //
- // Displays a 256 character array on screen. This can be single
- // or Double Byte data.
- //
- // Maintain 2 local arrays of chars. One is untouched, the other
- // contains the result of the Script Action currently selected.
- //
- //****************************************************************************
-
- #ifdef PowerPlant_PCH
- #include PowerPlant_PCH
- #endif
-
- // system headers
- #include <Script.h>
- #include <TextUtils.h>
-
- // PowerPlant headers
- #include <LStream.h>
- #include <UDrawingState.h>
-
- // project headers
- #include "LG_Constants.h"
- #include "CLG_CharsGrid.h"
-
-
- //***********************
- // CreateDisplayStream
- //****************************************************************************
- CLG_CharsGrid*
- CLG_CharsGrid::CreateDisplayStream(
- LStream *inStream)
- {
- return (new CLG_CharsGrid(inStream));
- }
-
-
- //***********************
- // CLG_CharsGrid
- //****************************************************************************
- CLG_CharsGrid::CLG_CharsGrid(void)
- {
- this->Init();
- return;
- }
-
- //***********************
- // CLG_CharsGrid
- //****************************************************************************
- CLG_CharsGrid::CLG_CharsGrid( LStream *inStream)
- : LPane( inStream)
- {
- this->Init();
- return;
- }
-
- //***********************
- // Init
- //****************************************************************************
- void CLG_CharsGrid::Init(void)
- {
- mBaseChar = 0;
- mFontNum = -1;
- mFontSiz = 14;
-
- mCurScriptNum = smRoman;
- mScriptAction = saNoChange;
-
- FillCodePts();
-
- return;
- }
-
-
- //***********************
- // FillCodePts
- // Relies on mBaseChar to be valid
- //****************************************************************************
- void CLG_CharsGrid::FillCodePts(void)
- {
- short cnt;
-
- if ( mBaseChar == 0) {
- for ( cnt=0;cnt<256;cnt++) {
- mCodePts[ cnt] = cnt;
- }
- } else {
- for ( cnt=0;cnt<256;cnt++) {
- mCodePts[ cnt] = (mBaseChar<<8) + cnt;
- }
- }
- BlockMoveData( mCodePts, mChars, sizeof(unsigned short)*256);
-
- return;
- }
-
-
- //***********************
- // ClickSelf
- //****************************************************************************
- void
- CLG_CharsGrid::ClickSelf( const SMouseDownEvent &inMouseDown)
- {
- return;
- }
-
-
- //***********************
- // AdjustCursorSelf
- //****************************************************************************
- void
- CLG_CharsGrid::AdjustCursorSelf(
- Point inPortPt ,
- const EventRecord& inMacEvent)
- {
- Point tPt;
- static Rect savR = {0,0,0,0};
-
-
- tPt = inPortPt;
-
- //Debugger();
-
- CursHandle theCursH = ::GetCursor( 2);
- if (theCursH != nil) {
- ::SetCursor(*theCursH);
- }
- }
-
-
- //***********************
- // DrawSelf
- //****************************************************************************
- // Why do I have to offset these locations?
-
- void CLG_CharsGrid::DrawSelf(void)
- {
- SDimension16 tFrame;
- Rect tR;
- short cntH, cntV;
-
- GetFrameSize( tFrame);
-
- PenNormal();
- MoveTo( 0, mFrameLocation.v+1 );
- Line( tFrame.width, 0);
- MoveTo( 0, mFrameLocation.v+tFrame.height-1 );
- Line( tFrame.width, 0);
-
- TextFont( mFontNum); TextSize( mFontSiz);
- TextFace(0); TextMode( srcOr);
-
- PenPat( &qd.gray);
- PenMode( patOr);
-
- for ( cntV=0; cntV<=16; cntV++) {
- MoveTo( mFrameLocation.h+ kcgHOffset, mFrameLocation.v+ kcgVOffset+ kcgVSpacing*cntV);
- Line( 16*kcgHSpacing, 0);
- }
- for ( cntH=0; cntH<=16; cntH++) {
- MoveTo( mFrameLocation.h+ kcgHOffset +kcgHSpacing*cntH, mFrameLocation.v+ kcgVOffset);
- Line( 0, 16*kcgVSpacing);
- }
- // Add informative gray spots for Kanji only
- if ( mBaseChar != 0 && mCurScriptNum == smJapanese) {
-
- for ( cntH=0; cntH<16; cntH++) {
- tR.left = mFrameLocation.h+ kcgHOffset +kcgHSpacing*cntH +2;
- tR.right = mFrameLocation.h+ kcgHOffset +kcgHSpacing*(1+cntH) -1;
- tR.top = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*0 +2;
- tR.bottom = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*1 -1;
- FillRect( &tR, &qd.gray);
- }
- for ( cntH=0; cntH<16; cntH++) {
- tR.left = mFrameLocation.h+ kcgHOffset +kcgHSpacing*cntH +2;
- tR.right = mFrameLocation.h+ kcgHOffset +kcgHSpacing*(1+cntH) -1;
- tR.top = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*1 +2;
- tR.bottom = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*2 -1;
- FillRect( &tR, &qd.gray);
- }
- for ( cntH=0; cntH<16; cntH++) {
- tR.left = mFrameLocation.h+ kcgHOffset +kcgHSpacing*cntH +2;
- tR.right = mFrameLocation.h+ kcgHOffset +kcgHSpacing*(1+cntH) -1;
- tR.top = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*2 +2;
- tR.bottom = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*3 -1;
- FillRect( &tR, &qd.gray);
- }
- for ( cntH=0; cntH<16; cntH++) {
- tR.left = mFrameLocation.h+ kcgHOffset +kcgHSpacing*cntH +2;
- tR.right = mFrameLocation.h+ kcgHOffset +kcgHSpacing*(1+cntH) -1;
- tR.top = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*3 +2;
- tR.bottom = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*4 -1;
- FillRect( &tR, &qd.gray);
- }
-
- cntH = 15;
- tR.left = mFrameLocation.h+ kcgHOffset +kcgHSpacing*cntH +2;
- tR.right = mFrameLocation.h+ kcgHOffset +kcgHSpacing*(1+cntH) -1;
- tR.top = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*7 +2;
- tR.bottom = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*8 -1;
- FillRect( &tR, &qd.gray);
-
- cntH = 13;
- tR.left = mFrameLocation.h+ kcgHOffset +kcgHSpacing*cntH +2;
- tR.right = mFrameLocation.h+ kcgHOffset +kcgHSpacing*(1+cntH) -1;
- tR.top = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*15 +2;
- tR.bottom = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*16 -1;
- FillRect( &tR, &qd.gray);
-
- cntH = 14;
- tR.left = mFrameLocation.h+ kcgHOffset +kcgHSpacing*cntH +2;
- tR.right = mFrameLocation.h+ kcgHOffset +kcgHSpacing*(1+cntH) -1;
- tR.top = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*15 +2;
- tR.bottom = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*16 -1;
- FillRect( &tR, &qd.gray);
-
- cntH = 15;
- tR.left = mFrameLocation.h+ kcgHOffset +kcgHSpacing*cntH +2;
- tR.right = mFrameLocation.h+ kcgHOffset +kcgHSpacing*(1+cntH) -1;
- tR.top = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*15 +2;
- tR.bottom = mFrameLocation.v+ kcgVOffset+ kcgVSpacing*16 -1;
- FillRect( &tR, &qd.gray);
-
- }
-
- PenNormal();
-
- for ( cntV=0; cntV<16; cntV++) {
- for ( cntH=0; cntH<16; cntH++) {
- MoveTo( mFrameLocation.h+ kcgHOffset+ kcgHSpacing*cntH +4,
- mFrameLocation.v+ kcgVOffset+ kcgVSpacing*(cntV+1) -3);
- if ( mBaseChar == 0) {
- // simple ascii. Use our shorts, make sure we get only 1 byte
- DrawChar( 0x00FF & mChars[ 16*cntV + cntH]);
- } else {
- // multi-byte
- DrawText( mChars, (16*cntV + cntH)*sizeof(short), 2);
- }
- }
- }
-
- return;
- }
-
-
- //***********************
- // DoPageUp, DoPageDown
- //
- // We get a msg that the user wants to change the char range.
- // Use knowledge about Script Systems to only change to char ranges that
- // make sense.
- //****************************************************************************
-
- void CLG_CharsGrid::DoPageUp()
- {
- if ( mCurScriptNum == smJapanese) {
- if ( mBaseChar < MAX_KanjiLeadByte) {
- do { mBaseChar++;
- } while ( !KanjiIsLeadByte(mBaseChar));
- FillCodePts();
- this->Refresh();
- } else if ( mBaseChar == MAX_KanjiLeadByte) {
- mBaseChar = 0;
- FillCodePts();
- this->Refresh();
- } else {
- SysBeep(1);
- }
- } else {
- if ( mBaseChar == 0) mBaseChar = 128;
- else if ( mBaseChar == 255) mBaseChar = 0;
- else mBaseChar++;
-
- FillCodePts();
- this->Refresh();
- }
- }
- //***********************
-
- void CLG_CharsGrid::DoPageDown()
- {
- if ( mCurScriptNum == smJapanese) {
- if ( mBaseChar > MIN_KanjiLeadByte) {
- do { mBaseChar--;
- } while ( !KanjiIsLeadByte(mBaseChar));
- FillCodePts();
- this->Refresh();
- } else if ( mBaseChar == MIN_KanjiLeadByte) {
- mBaseChar = 0;
- FillCodePts();
- this->Refresh();
- } else {
- SysBeep(1);
- }
- } else {
- if ( mBaseChar == 0) mBaseChar = 255;
- else if ( mBaseChar == 128) mBaseChar = 0;
- else mBaseChar--;
-
- FillCodePts();
- this->Refresh();
- }
- }
-
-
- //***********************
- // DoChangeChars
- //****************************************************************************
- void
- CLG_CharsGrid::DoChangeChars()
- {
- short cnt;
-
- long scripNum = GetScriptManagerVariable( smKeyScript);
-
- // re-init the array of chars so no ScriptMgr actions accumulate
- BlockMoveData( mCodePts, mChars, sizeof(unsigned short)*256);
-
- // perform the script action for each char in the array
- // if we have DblByte data, use different Ptr arithmatic
- if ( mScriptAction != saNoChange) {
- for ( cnt=0;cnt<256;cnt++) {
- if ( mBaseChar == 0) {
- // simple ascii
- switch (mScriptAction) {
- case saUppercase:
- UppercaseText( ((Ptr)mChars) +cnt*2 +1, 1, scripNum);
- break;
- case saLowercase:
- LowercaseText( ((Ptr)mChars) +cnt*2 +1, 1, scripNum);
- break;
- case saStripDiacritical:
- StripDiacritics( ((Ptr)mChars) +cnt*2 +1, 1, scripNum);
- break;
- case saUpperStripDiacritical:
- UppercaseStripDiacritics( ((Ptr)mChars) +cnt*2 +1, 1, scripNum);
- break;
- };
- } else {
- switch (mScriptAction) {
- case saUppercase:
- UppercaseText( ((Ptr)mChars) +cnt*2, 2, scripNum);
- break;
- case saLowercase:
- LowercaseText( ((Ptr)mChars) +cnt*2, 2, scripNum);
- break;
- case saStripDiacritical:
- StripDiacritics( ((Ptr)mChars) +cnt*2, 2, scripNum);
- break;
- case saUpperStripDiacritical:
- UppercaseStripDiacritics( ((Ptr)mChars) +cnt*2, 2, scripNum);
- break;
- };
- }
- }
- }
-
- this->Refresh();
-
- return;
- }
-
- //*****************************************************************************
-